package com.hytc.controller;

import com.hytc.entity.User;
import com.hytc.service.UserService;
import com.hytc.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.ParameterMetaData;
import java.time.LocalDateTime;
import java.util.Date;

public class RegisterServlet extends HttpServlet {
    private UserService userService=  new UserServiceImpl();


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /**
         * 获取用户名密码邮箱 传到数据库
         */
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String email = req.getParameter("email");
        if(userService.existsUsername(username)){
            System.out.println("用户名"+username+"已存在");
            req.getRequestDispatcher("/register.jsp").forward(req,resp);
            System.out.println("请重新注册用户名");
        }else {
            System.out.println("已注册成功");
            userService.registerUser(new User(null,username,password,email,null,null,null,null,null));
            req.getRequestDispatcher("/register_success.jsp").forward(req,resp);
        }
    }
}
